package com.hans.scala.actor

import scala.actors._, Actor._

/**
 *
 * Created by Hans on 2014/4/9 .
 */
object SillyActor extends Actor {
  def act() {
    for (i <- 1 to 5) {
      println("i'm acting")
      Thread.sleep(1000)
    }
  }

  def main(args: Array[String]) {
    //    SillyActor.start()

    val sillyActor2 = actor {
      def emoteLater() {
        val mainActor = self
        actor {
          Thread.sleep(1000)
          mainActor ! "Emote"
        }
      }

      var emoted = 0
      emoteLater()

      loop {
        react {
          case "Emote" =>
            println("I'm acting!")
            emoted += 1
            if (emoted < 5)
              emoteLater()
          case msg =>
            println("Received: " + msg)
        }
      }
    }
  }
}
